We can easily verify that none of the entries in the first seven rows of Pascal's triangle are divisible by 7:
However, if we check the first one hundred rows, we will find that only 2361 of the 5050 entries are not divisible by 7.
Find the number of entries which are not divisible by 7 in the first one billion (10^9) rows of Pascal's triangle.
In [1]:
def f(n):
if n == 0:
return 1
return (1+(n%7))*f(n//7)
def F(n):
if n == 0:
return 0
r = n % 7
return 28*F(n//7) + r*(r+1)//2*f(n//7)
print(F(10**9))
In [ ]: